<template>
  <div class="table-page-search-wrapper">
    <a-card>
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :md="6" :sm="12">
            <a-form-item label="开课学年">
              <a-select allowClear v-model="queryParam.kkxn">
                <a-select-option v-for="i in TYPE0125" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12">
              <a-form-item label="开课学期">
                <a-select allowClear v-model="queryParam.kkxqm">
                  <a-select-option v-for="i in TYPE0072" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          <template v-if="advanced">
            <a-col :md="6" :sm="12">
              <a-form-item label="课程代码">
                <a-input v-model="queryParam.kcbm"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="12">
              <a-form-item label="课程名称">
                <a-input v-model="queryParam.kcmc"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="12">
              <a-form-item label="任课教师编号">
                <a-input v-model="queryParam.rkjszgh"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="12">
              <a-form-item label="任课教师">
                <a-input v-model="queryParam.rkjsxm"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="16" :sm="20">
            <span class="table-page-search-submitButtons" >
            <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
            <a-button type="primary" @click="exportExl">导出</a-button>

            </span>
          </a-col>
        </a-row>
      </a-form>
    </a-card>

    <a-card :bordered="false" style="margin-top: 10px">
      <a-alert message="评教分数非固定分数，会因之后提交的评教分数产生变化！" type="info" show-icon />
      <s-table
        ref="table"
        size="default"
        :columns="columns"
        :data="loadData"
        :alert="{ show: false }"
        :pageSize="parameter.pageSize"
        :pageNum="parameter.pageNum"
      >
        <!-- <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 + (parameter.pageNo - 1) * parameter.pageSize }}
        </span> -->
        <template slot="operation" slot-scope="a,b">
            <a @click="showDetail(b)">详情</a>
            <a @click="showAdvise(b)">意见建议</a>
        </template>
      </s-table>
    </a-card>
    <com-teach-detail-ad :visible="detailVisible" @cancel="detailVisible = false" :confirmLoading="confirmLoading" :courseInfo="courseInfo" :typeUser="'stu'"/>
    <com-teach-advise :adviseVisible="adviseVisible" @cancelAd="adviseVisible = false" :confirmAdLoading="confirmAdLoading" :courseInfo="courseInfo" :typeUser="'stu'"/>

  </div>
</template>

<script>
import { STable } from '~'
import { mapState } from 'vuex'
import comTeachDetailAd from './comTeachDetailAd'
import comTeachAdvise from './comTeachAdvise'
// import courseDetail from '../courseDetail'
// import searchMixin from '@/utils/searchRemain'

export default {
//   mixins: [ searchMixin ],
  data () {
    return {
      advanced: true,
      queryParam: {kkxn: '',kkxqm: ''},
      columns: [
        // {
        //   title: '序号',
        //   scopedSlots: { customRender: 'serial' }
        // },
        {
          title: '课程代码',
          dataIndex: 'kcbm'
        },
        {
          title: '课程名称',
          dataIndex: 'kcmc'
        },
        {
          title: '开课学年',
          dataIndex: 'kkxn'
        },
        {
          title: '开课学期',
          dataIndex: 'kkxqm',
           customRender: (value, row, index) => {
               if(value == 1){
                   return '秋季学期'
               }else{
                   return '春季学期'
               }
           }
        },
        {
          title: '开课院系',
          dataIndex: 'kkyxmc'
        },
        {
          title: '教学态度',
          dataIndex: 'pj01',
          customRender: (value, row, index) => {
            return value.toFixed(2)
          }
        },
       
        {
          title: '教学内容',
          dataIndex: 'pj02',
          customRender: (value, row, index) => {
            return value.toFixed(2)
          }
        },
        {
          title: '教学方法',
          dataIndex: 'pj03',
          customRender: (value, row, index) => {
            return value.toFixed(2)
          }
        },
        {
          title: '教学效果',
          dataIndex: 'pj04',
          customRender: (value, row, index) => {
            return value.toFixed(2)
          }
        },
        {
          title: '操作',
          width: '160px',
          dataIndex: 'operation',
          fixed: 'right',
          scopedSlots: { customRender: 'operation' }
        }
      ],
      parameter: {
        pageNo: 1,
        pageSize: 10
      },
      loadData: parameter => {
        if(!this.initDone) return
        this.parameter = parameter
        parameter.pageNum = parameter.pageNo
        let params = Object.assign(this.queryParam, parameter)
        return this.$api.student.stuComTeachAdlist(params).then(res => {
          return {
            data: res.data.rows,
            pageNo: parameter.pageNum,
            pageSize: parameter.pageSize,
            totalPage: Math.ceil(res.data.total / parameter.pageSize),
            totalCount: res.data.total
          }
        })
      },
      selectMenu: {
        yx: []
      },
      detailVisible: false,
      adviseVisible: false,
      confirmLoading: false,
      confirmAdLoading: false,
      courseInfo: {},
      initDone: false
    }
  },
  components: {STable,comTeachDetailAd,comTeachAdvise},
  computed: {
    ...mapState({
      TYPE0125: state => state.app['TYPE0125'],
      TYPE0072: state => state.app['TYPE0072'],
    })
  },
  created () {
    this.$store.dispatch('app/setDictionary', 'TYPE0125')
    this.$store.dispatch('app/setDictionary', 'TYPE0072')
    this.initSelectMenu()
    this.$store.dispatch('app/sysInfo').then(res => {
      console.log(res,11)
      this.initDone = true
      this.queryParam.kkxn = res.schoolYear
      this.queryParam.kkxqm = res.currentSemester
      this.$refs.table.refresh()
    })
  },
  methods: {
    filterOption (value, op) {
      return op.componentOptions.children[0].text.indexOf(value) !== -1
    },
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data
        }
        if(this.selectMenu.yx && this.selectMenu.yx.length == 1){
          this.$set(this.queryParam, 'kcssyxm', this.selectMenu.yx[0].dwh)
        }
        this.initDone = true
      })
    },
    
    showDetail (course) {
    //   this.confirmLoading = true
        this.courseInfo = course
      this.detailVisible = true
    },
    showAdvise(course){
        this.courseInfo = course
        this.confirmAdLoading = true
        this.adviseVisible = true
    },
    exportExl(){
      let params = this.queryParam
      delete params.pageNo
      delete params.pageNum
      delete params.pageSize
      console.log(params)
      this.$export('/kcpjzb/xsManage/export', {
        ...params
      })
    }
  }
}
</script>

<style>

</style>
